// pages/companyDetail/companyDetail.js
var common = require("../../utils/util.js");
Page({

  /**
   * 页面的初始数据
   */
  data: {
    navList: ['公司信息','公司展品'],
    navIndex: 0,
    goodsList: [],
      info:'',
      followStatus: 1,  //1未收藏 2已收藏
      atrID: ''
  },

    changeNav: function (e) {
      this.setData({
          navIndex: e.currentTarget.dataset.i
      });
    },
    follow: function () {
        var that = this;
        var openId = getApp().globalData.openId;
        common.ajax({
            url: 'PersonMain/CollectionCancellation',
            data: {
                sourceType: 1,
                sourceId: openId,
                tragetType: 1,
                tragetId: that.data.atrID
            },
            loading: '加载中...',
            userinfo: false,
            success: function (res) {
                if (res.message == 'success') {
                    that.setData({
                        followStatus: res.resultCol
                    });
                    console.log('收藏结果'+res.resultCol)
                    console.log(res)
                } else {
                    console.log(res)
                }
            }
        });
    },
    goodsDetail: function (e) {
        var index = e.currentTarget.dataset.i;
        var goodsId = this.data.goodsList[0].ID;
        wx.navigateTo({
            url: '../goodsDetail/goodsDetail?goodsId=' + goodsId
        })
    },
    home: function () {
      wx.navigateBack({
          delta:2
      });
    },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
      var openId = getApp().globalData.openId;
      var atrID = options.atrID;
      var that = this;
      common.ajax({
          url: 'Actor/GetDetails',
          data: {
              atrID: atrID,
              openId: openId
          },
          loading: '加载中...',
          userinfo: false,
          success: function (res) {
              if (res.message == 'success') {
                  that.setData({
                      info: res.data,
                      followStatus: res.data.IsCollection,
                      goodsList: res.data.ListProductEntity,
                      atrID: atrID
                  });
                  wx.setNavigationBarTitle({
                      title: that.data.info.AtrName
                  });
                  console.log('是否收藏'+res.data.IsCollection)
                  console.log(res)
              } else {
                  console.log(res)
              }
          }
      });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})